// components/good/good.js
import util from '../../../utils/utils'
import {
  HomeHttp
} from '../../../api/home.js'
const homeModel = new HomeHttp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    typeInfo: Object, // 商品信息
    show: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    freeStatus: {
      1: true,
      3: true,
      4: true,
      5: true,
      10: true,
      11: true,
      12: true,
      15: true
    }, //免单按钮显示
    afterSaleStatus: {

    } //售后按钮显示

  },
  /**
   * 组件的方法列表
   */
  methods: {
    //点击取消按钮
    onFreeofCharge() {
      this.triggerEvent('FreeofCharge')
    },
    onCancelOrder() {
      this.triggerEvent('cancelOrder')
    },
    onAgainbtn() {
      this.triggerEvent('againOrder')
    },
    onAfterSalebtn() {
      this.triggerEvent('afterSale')
    },
    onPaybtn() {
      this.triggerEvent('pay')
    },
    onContactExpressbtn() {
      this.triggerEvent('contactExpress')
    },
    getAddress(e) {
      this.triggerEvent('getAddress', this.data.typeInfo);
    },
    //拨打店铺电话/
    onContact() {
      wx.makePhoneCall({
        phoneNumber: this.data.typeInfo.storePhone,
      });
    },
    toPage(){
      const { fatherOrderId, orderSourceType, receiveType } = this.data.typeInfo
      // orderSourceType 订单来源类型 --- 1: 巷友, 2: 1688, 3: 积分兑换订单
      // receiveType 提货方式 --- 1: 门店自提, 2: 门店配送
      wx.navigateTo({
        url: `/pages/order/comment/comment?id=${fatherOrderId}&sourceType=${orderSourceType}&receiveType=${receiveType}`,
      })
    },
    //确认收货
    confirmBtn() {
      let self = this
      wx.showModal({
        title: '是否确认收货',
        success: function(res) {
          if (res.confirm) {
            homeModel.getFinishOrder({
              orderNumber: self.data.typeInfo.fatherOrderId
            }).then((res) => {
              self.triggerEvent('refreshData')
            }).catch((err) => {
              self.triggerEvent('refreshData')
            })

          }
        },
      })
    },
    onLookDeliver(){
      wx.navigateTo({
        url: '/pages/order/flow/flow?id='+this.data.typeInfo.fatherOrderId,
      })
    },
    //点评
    onComment() {
      wx.showModal({
        title: '温馨提示',
        content: '评论请下载巷友APP进行评论',
        cancelText: "再想想",
        confirmColor: '#F93B3B',
        confirmText: "去下载",
        success: function() {},
        fail: function() {},
        complete: function() {}
      })
    },
  }
});
